from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from app.db.session import get_db

router = APIRouter()


@router.get("/", summary="健康检查")
def health_check():
    """
    执行健康检查
    """
    return {"status": "ok", "message": "服务运行正常"}


@router.get("/db", summary="数据库健康检查")
def database_health_check(db: Session = Depends(get_db)):
    """
    检查数据库连接
    """
    try:
        # 执行简单查询
        db.execute("SELECT 1")
        return {"status": "ok", "message": "数据库连接正常"}
    except Exception as e:
        return {"status": "error", "message": f"数据库连接失败: {str(e)}"} 